package com.xbongbong.pro.enums.fund.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 管理方式枚举
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum ManageTypeEnum {

    /**
     * 管理方式：1无账期，2企业统一管理账期，3根据客户管理账期，4根据合同订单管理账期
     */
    NONE(1,"enum.manageType.name.none", XbbRefTypeEnum.UNKNOWN),
    CORP(2,"enum.manageType.name.corp", XbbRefTypeEnum.SYSTEM),
    CUSTOMER(3,"enum.manageType.name.customer", XbbRefTypeEnum.CUSTOMER_MANAGEMENT),
    CONTRACT(4,"enum.manageType.name.contract", XbbRefTypeEnum.CONTRACT),
    ;

    /**
     * 模式code
     */
    private Integer code;

    /**
     * 模式名称
     */
    private String name;

    /**
     * 业务类型
     */
    private XbbRefTypeEnum xbbRefTypeEnum;


    ManageTypeEnum(Integer code, String name, XbbRefTypeEnum xbbRefTypeEnum){
        this.code = code;
        this.name = name;
        this.xbbRefTypeEnum = xbbRefTypeEnum;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getI18nName() {
        return name;
    }

    /**
     * 根据code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.fund.enums.ManageTypeEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static ManageTypeEnum getByCode(Integer code){
        for (ManageTypeEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        return null;
    }

    public static ManageTypeEnum[] getStatementRule() {
        ManageTypeEnum[] enums = new ManageTypeEnum[2];
        enums[0] = ManageTypeEnum.CORP;
        enums[1] = ManageTypeEnum.CUSTOMER;
        return enums;
    }
}
